<?php

	/**
	 *
	 * @param mixed $var
	 */
	function dump($var){
		echo '<pre>';
		echo var_dump($var);
		echo '</pre>';
	}
	
	/**
	 *
	 * @param string $birthday yyyy-mm-dd
	 * @return age
	 */
	function getAge($birthday){
		list($year,$month,$day) = explode("-",$birthday);
		$year_diff  = date("Y") - $year;
		$month_diff = date("m") - $month;
		$day_diff   = date("d") - $day;
		if ($day_diff < 0 || $month_diff < 0)
		$year_diff--;
		return $year_diff;
	}
	
	/**
	 *
	 * @staticvar array $register
	 * @param string $data
	 * @param mixed $value
	 * @return mixed
	 */
	function &data($key, $value = null){
		static $register;
		
		if($value !== null){
			$register[$key] =& $value;
		}
		
		return $register[$key];
	}
	
	/**
	 *
	 * @param string $date dd-mm-yyyy
	 * @return string mysql format dd-mm-yyyy
	 */
	function dateToMysqlFormat($date){
		$eDate = explode('/', $date);
		return $eDate[2] . '-' . $eDate[0] . '-' . $eDate[1];
	}
	
	/**
	 *
	 * @param float $mt_old microtime
	 * @param float $mt_new microtime
	 * @return float
	 */
	function microtimeDiff($mt_old, $mt_new = null)
	{
		if($mt_new === null){
			$mt_new = microtime();
		}
		
		list($old_usec, $old_sec) = explode(' ', $mt_old);
		list($new_usec, $new_sec) = explode(' ', $mt_new);
		$old_mt = ((float)$old_usec + (float)$old_sec);
		$new_mt = ((float)$new_usec + (float)$new_sec);
		return $new_mt - $old_mt;
	}
	
	/**
	 *
	 * @param string $file name of the view file
	 */
	function displayView($file){
		include(APP_PATH . 'views' . DIRECTORY_SEPARATOR . $file . '.phtml');
	}
	
	/**
	 *
	 * @param string $key
	 * @return [$key] if the word was not found in the dictionary.
	 */
	function translate($key){
		$lang = array(
			'in a relationship' => 'in een relatie'
		);
		
		return isset($lang[$key]) ? $lang[$key] : '[' . $key . ']';
	}
	
// File end.